package utils;


import org.apache.commons.lang3.StringUtils;
import pojo.ListNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author chengshijian
 * @Date 2022/2/11 16:27
 */
public class PrintUtil {

    public static void printArr(int[] nums) {
        Integer[] newNums = new Integer[nums.length];
        for (int i = 0; i < nums.length; i++) {
            newNums[i] = nums[i];
        }
        System.out.println("[" + StringUtils.join(newNums, ",") + "]");
    }

    public static void printLinkedList(ListNode head) {
        printLinkedList(head, false);
    }

    public static void printLinkedList(ListNode head, boolean haveHead) {
        List<Integer> list = new ArrayList<>();
        for (ListNode p = haveHead ? head.next : head; p != null; p = p.next) {
            list.add(p.val);
        }
        System.out.println(list);
    }

    public static <T> void printList(List<T> list) {
        System.out.println(list);
    }

}
